<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="bean.User,dao.UserDao"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<style>
.a {
	font-size: 22px;
}

.input {
	height: 40px;
	width: 200px;
	background-color: white;
	border: 1px;
	/* 	order-collapse:10px; 	 */
}
</style>

<body>
	<%
		request.setCharacterEncoding("UTF-8");//对获取到的数据进行乱码处理

		User user = new User();
		UserDao dao = new UserDao();
		user = (User) session.getAttribute("user");
		String loginId = user.getLoginId();
		user = dao.getUserByLoginId(loginId);
		String gender = user.getGender();
	%>
	<script type="text/javascript">
		function btn_okClick() {

			var userName = frm_register.userName.value;
			if (userName == "") {
				alert("昵称不能为空！");
				frm_register.userName.focus();//聚焦
				return false;
			}
			if (userName.length > 20) {
				alert("购物名不能超过20个字符，请重新输入！")
				frm_register.userName.select();//回显 
				return false;
			}

			var email = frm_register.email.value;
			if (email == "") {
				alert("邮箱不能为空！");
				frm_register.email.focus();//聚焦
				return false;
			}

			if (email.length < 6) {
				alert("邮箱长度不够，请重新输入！")
				frm_register.email.select();//回显
				frm_register.email.focus();//聚焦
				return false;

			}

			if (email.length >= 18) {
				alert("邮箱长度过长，请重新输入！")
				frm_register.email.select();//回显
				frm_register.email.focus();//聚焦
				return false;

			}
			if (email != "" && !/^\w(\w*\.*)*@(\w+\.)+\w{2,4}$/.test(email)) {
				alert("邮箱格式不正确!");
				frm_register.email.select();//回显
				frm_register.email.focus();//聚焦
				return false;

			}

			var telephone = frm_register.telephone.value;
			if (telephone == "") {
				alert("电话不能为空！");
				frm_register.telephone.focus();//聚焦
				return false;
			}
			if (telephone.length > 12) {
				alert("电话不合法，请重新输入！");
				frm_register.telephone.select();//回显
				frm_register.telephone.focus();//聚焦
				return false;
			}

			var sexNum = document.getElementsByName("gender"); //获取radio对象组，返回值是数组类型的
			var gender = ""; //用于保存用户的选项
			for (var i = 0; i < sexNum.length; ++i) { //循环便利查看用户的选择项
				if (sexNum[i].checked) { //checked代表用户的选择
					gender = sexNum[i];
				}
			}
			if (gender == "") { //gender为空代表用户没有选择
				alert("请选择性别!");
				return false;
			}

			return true;
			// 	frm_register.submit();//提交表单到服务器
		}

		function sub_button() {
			// 	alert(1)
			var result = btn_okClick();

			if (result != false) {

				frm_register.submit();//提交表单到服务器
			}
			// 	document.getElementById("loginId").value //获取文本框的内容；
		}
	</script>
	<h2>我的信息</h2>
	<hr color="pink">
	<form action="../ModifyManager" method="post" name="frm_register">
		<!-- border="1" cellspacing="0" cellpadding="0" width="50" -->
		<table align="center" border="0" cellspacing="10" cellpadding="0">


			<!-- id="useridSpan"    οnblur="checkUserid()     id="userid"  -->
			<!-- <input type="text" disabled="disabled" value="你想要显示的内容"> -->
			<!-- <input type="text" readonly value="你想要显示的内容">    disabled="disabled"-->
			<tr>
				<td class="a">账号：</td>
				<td><input type="text" name="loginId" size="40" readonly
					value="<%=user.getLoginId()%>" border="0" class="input"></td>
			</tr>

			<tr>
				<td class="a">昵称：</td>
				<td><input type="text" name="userName"
					value="<%=user.getUserName()%>" class="input"></td>
			</tr>

			<tr>
				<td class="a">姓名：</td>
				<td><input type="text" name="realName"
					value="<%=user.getRealName()%>" disabled="disabled" border="0"
					class="input"></td>
			</tr>


			<tr>
				<td class="a">性别：</td>
				<td>
					<%
						if (gender.equals("0")) {
					%> <input type="radio" name="gender" value="0" class="userSex"
					class="input" checked><font size="4">男</font> <input
					type="radio" name="gender" value="1" class="userSex" class="input"><font
					size="4">女</font> <%
 					}
					if (gender.equals("1")) {
 %> <input type="radio" name="gender" value="0" class="userSex"
					class="input"><font size="4">男</font> <input type="radio"
					name="gender" value="1" class="userSex" class="input" checked><font
					size="4">女</font> <%
 	}
 %>

				</td>
			</tr>

			<tr>
				<td class="a">邮箱：</td>
				<td><input type="text" name="email"
					value="<%=user.getEmail()%>" maxlength="18"
					onKeyUp="value=value.replace(/[^\w\.\@\/]/ig,'')" class="input">
				</td>
			</tr>

			<tr>
				<td class="a">电话：</td>
				<td><input type="text" name="telephone"
					value="<%=user.getTelephone()%>" size="12" class="input"
					onKeyUp="value=value.replace(/[^\d|chun]/g,'')" maxlength="11">
				</td>
			</tr>



			<tr>
				<td colspan="2" align="center">
					<!-- <input type="submit" name="smt_ok" value="注册"> --> <input
					type="button" onclick="sub_button()" value="确认修改"
					style="width: 100px; height: 40px;"> <!-- <input type="reset" name="rst_cancel" value="重置" style="width:80px;height:30px;"> -->
					<input type="button" value="返回" onclick="goback();"
					style="width: 100px; height: 40px;">
				</td>
			</tr>
		</table>
	</form>
	<script>
		function goback() {
			// 	window.history.back(-1);
			// 	window.location.reload();
			window.location.href = "show.jsp";
		}
	</script>


</body>
</html>